﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;

namespace SchoolManagementSystem.Report._3._KeToan
{
    public partial class BaoCaoChiTietHocPhiChuyenNghiep : DevExpress.XtraReports.UI.XtraReport
    {
        public BaoCaoChiTietHocPhiChuyenNghiep()
        {
            InitializeComponent();
           
        }

        public string time6lan = "";
        public string time4lan = "";
        int STT = 0;
      
        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            STT++;
            xrTableCell_STT.Text = STT.ToString();
            try {

                var money1 = (long)GetCurrentColumnValue("Money1Ext");
                var money2 = (long)GetCurrentColumnValue("Money2Ext");
                var money3 = (long)GetCurrentColumnValue("Money3Ext");
                var money4 = (long)GetCurrentColumnValue("Money4Ext");
                var money5 = (long)GetCurrentColumnValue("Money5Ext");
                var money6 = (long)GetCurrentColumnValue("Money6Ext");
               
                var type = (int)GetCurrentColumnValue("TypeExt");
                if (type == 1)
                {
                    xrTableCell_money1.WidthF = (float)114.18;
                    xrTableCell_money2.WidthF = (float)119.95;
                    xrTableCell_money3.WidthF = (float)128.73;
                    xrTableCell_money4.WidthF = (float)121.43;
                    xrTableCell_money5.WidthF = (float)108.49;
                    xrTableCell_money6.WidthF = (float)120.99;
                    xrTableCell_money1.Borders =   DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left;
                    xrTableCell_money2.Borders = DevExpress.XtraPrinting.BorderSide.Top;
                    xrTableCell_money3.Borders =  DevExpress.XtraPrinting.BorderSide.Top;
                    xrTableCell_money4.Borders =  DevExpress.XtraPrinting.BorderSide.Top;
                    xrTableCell_money5.Borders =  DevExpress.XtraPrinting.BorderSide.Top;
                    xrTableCell_money6.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money3.Text = money1>0? String.Format("{0:c1}", (long)GetCurrentColumnValue("Money1Ext")):"";
                    xrTableCell_money1.Text="";
                    xrTableCell_money2.Text = "";
                    xrTableCell_money4.Text = "";
                    xrTableCell_money5.Text = "";
                    xrTableCell_money6.Text = "";
                }
                if (type == 2)
                {
                    xrTableCell_money1.WidthF = (float)114.18;
                    xrTableCell_money2.WidthF = (float)119.95;
                    xrTableCell_money3.WidthF = (float)128.73;
                    xrTableCell_money4.WidthF = (float)121.43;
                    xrTableCell_money5.WidthF = (float)108.49;
                    xrTableCell_money6.WidthF = (float)120.99;
                    xrTableCell_money1.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left;
                    xrTableCell_money2.Borders =  DevExpress.XtraPrinting.BorderSide.Top;
                    xrTableCell_money3.Borders =   DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money4.Borders = DevExpress.XtraPrinting.BorderSide.Top;
                    xrTableCell_money5.Borders =  DevExpress.XtraPrinting.BorderSide.Top;
                    xrTableCell_money6.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money2.Text = money1>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money1Ext")):"";
                    xrTableCell_money4.Text =money2>0? String.Format("{0:c1}", (long)GetCurrentColumnValue("Money2Ext")):"";
                     xrTableCell_money1.Text="";
                     xrTableCell_money3.Text = "";
                     xrTableCell_money5.Text = "";
                     xrTableCell_money6.Text = "";
                }

                if (type == 4)
                {
                    xrTableCell_money1.WidthF = (float)175.84;
                    xrTableCell_money2.WidthF = (float)185;
                    xrTableCell_money4.WidthF = (float)174;
                    xrTableCell_money5.WidthF = (float)174.47;
                    xrTableCell_money1.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left;
                    xrTableCell_money2.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left;
                    xrTableCell_money3.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money4.Borders = DevExpress.XtraPrinting.BorderSide.Top;
                    xrTableCell_money5.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left;
                    xrTableCell_money6.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money1.Text = money1>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money1Ext")):"";
                    xrTableCell_money2.Text = money2>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money2Ext")):"";
                    xrTableCell_money4.Text = money3>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money3Ext")):"";
                    xrTableCell_money5.Text = money4>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money4Ext")):"";
                    xrTableCell_money3.Text = "";
                    xrTableCell_money6.Text = "";
                }


                if (type == 6)
                {
                    xrTableCell_money1.WidthF = (float)114.18;
                    xrTableCell_money2.WidthF = (float)119.95;
                    xrTableCell_money3.WidthF = (float)128.73;
                    xrTableCell_money4.WidthF = (float)121.43;
                    xrTableCell_money5.WidthF = (float)108.49;
                    xrTableCell_money6.WidthF = (float)120.99;
                    xrTableCell_money1.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money2.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money3.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money4.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money5.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money6.Borders = DevExpress.XtraPrinting.BorderSide.Top | DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right;
                    xrTableCell_money1.Text = money1>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money1Ext")):"";
                    xrTableCell_money2.Text = money2>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money2Ext")):"";
                    xrTableCell_money3.Text = money3>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money3Ext")):"";
                    xrTableCell_money4.Text = money4>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money4Ext")):"";
                    xrTableCell_money5.Text = money5>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money5Ext")):"";
                    xrTableCell_money6.Text = money6>0?String.Format("{0:c1}", (long)GetCurrentColumnValue("Money6Ext")):"";
                }

                var discount = GetCurrentColumnValue("DiscountExt");
                xrTableCell_Discount.Text = discount.ToString() + " %";
            }
            catch { }
        }

        private void ReportHeader_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
          //  xrLabel_Class.Text = "Lớp: " + ClassName;
          //  xrLabel_ClassSize.Text = "Sỉ số: " + ClassSize;
          //  xrLabel_Teacher.Text = "GVCN: " + Teacher;

            if (!String.IsNullOrEmpty(time4lan) && !String.IsNullOrEmpty(time6lan))
            {
                var thoigian4lan = time4lan.Split(',');
                var thoigia6lan = time6lan.Split(',');
                xrTableCell_time4lan1.Text = "Lần 1 - "+Environment.NewLine + thoigian4lan[0];
                xrTableCell_time4lan2.Text = "Lần 2 - " + Environment.NewLine + thoigian4lan[1];
                xrTableCell_time4lan3.Text = "Lần 3 - " + Environment.NewLine + thoigian4lan[2];
                xrTableCell_time4lan4.Text = "Lần 4 - " + Environment.NewLine + thoigian4lan[3];

                xrTableCell_time1lan1.Text = "Lần 1\r\n" + thoigia6lan[0];
                xrTableCell_time1lan2.Text = "Lần 2\r\n" + thoigia6lan[1];
                xrTableCell_time1lan3.Text = "Lần 3\r\n" + thoigia6lan[2];
                xrTableCell_time1lan4.Text = "Lần 4\r\n" + thoigia6lan[3];
                xrTableCell_time1lan5.Text = "Lần 5\r\n" + thoigia6lan[4];
                xrTableCell_time1lan6.Text = "Lần 6\r\n" + thoigia6lan[5];
            }
        }

        private void ReportFooter_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            xrLabel_datetime.Text = "Tp. Hồ Chí Minh, ngày "+DateTime.Now.Day+" tháng "+DateTime.Now.Month+" năm "+DateTime.Now.Year;
            xrLabel_Staff.Text = Helper.ValueDefine.StaffName;
        }

    }
}
